package com.xhsj.user.hr.system.web;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xhsj.user.hr.aspect.OperationPointCut;
import com.xhsj.user.hr.base.BaseParam;
import com.xhsj.user.hr.process.hrBecomeRegular.service.TbHrApprovalBecomeRegularApplyService;
import com.xhsj.user.hr.process.hrEntryProcess.service.TbHrApprovalEntryApplyService;
import com.xhsj.user.hr.process.hrInterviewRegistration.service.TbHrInterviewRegistrationService;
import com.xhsj.user.hr.process.processDefinition.query.MapQuery;
import com.xhsj.user.hr.system.vo.UserInfoToAppVo;
import com.xhsj.user.security.entity.LoginUser;
import com.xhsj.user.hr.system.dto.UpdateUserDetailDto;
import com.xhsj.user.hr.system.dto.UserListDto;
import com.xhsj.user.hr.system.mapper.TbGlobalOrganizationMapper;
import com.xhsj.user.hr.system.mapper.TbGlobalRoleMapper;
import com.xhsj.user.hr.system.mapper.TbGlobalUserMapper;
import com.xhsj.user.hr.system.query.LoadUserInfoQuery;
import com.xhsj.user.hr.system.query.UserListQuery;
import com.xhsj.user.hr.system.service.TbHrApprovalDimissionApplyService;
import com.xhsj.user.hr.system.vo.FindUserListVo;
import com.xhsj.user.hr.system.vo.GetUserLoginInfoVo;
import com.xhsj.user.utils.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.text.Collator;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.access.prepost.PreAuthorize;


import com.xhsj.user.hr.system.service.TbGlobalUserService;
import com.xhsj.user.hr.system.entity.TbGlobalUser;

import javax.validation.Valid;


/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author suxl
 * @since Aug 27, 2020 10:39:27 AM
 */
@Slf4j
@Api(tags = "用户信息表")
@RestController
@RequestMapping("/user/tbGlobalUser")
public class TbGlobalUserController {

	@Autowired
    public TbGlobalUserService service;

	@Autowired
	private ConsumerTokenServices tokenServices;

	@Autowired
	private TbGlobalOrganizationMapper tbGlobalOrganizationMapper;

	@Autowired
	private TbGlobalRoleMapper tbGlobalRoleMapper;

	@Autowired
	private TbHrInterviewRegistrationService tbHrInterviewRegistrationService;

	@Autowired
	private TbHrApprovalEntryApplyService TbHrApprovalEntryApplyService;

	@Autowired
	private TbHrApprovalBecomeRegularApplyService tbHrApprovalBecomeRegularApplyService;

	@Autowired
	private TbHrApprovalDimissionApplyService tbHrApprovalDimissionApplyService;

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	@Autowired
	private BCryptPasswordEncoder bCryptPasswordEncoder;

	@Autowired
	private TbGlobalUserMapper tbGlobalUserMapper;

	@Value("${rsa.privateKey}")
	private String privateKey;


	/**
	 * 保存/修改
	 * @author suxl
	 * @date Aug 27, 2020 10:39:27 AM
	 */
	@ApiOperation(value = "用户信息表,保存/修改", notes = "用户信息表,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
 	@PreAuthorize("hasAuthority('tb:sys:user:edit')")
	@OperationPointCut(module = "HR模块",operation = "用户信息表,保存/修改")
	public Message save(@RequestBody TbGlobalUser data){
    	try {
    		service.saveUser(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,e.getMessage());
		}

	}

	@ApiOperation(value = "获取用户登录信息", notes = "获取用户登录信息")
	@RequestMapping(value = "/getUserLoginInfo", method = RequestMethod.GET)
	public Message getUserLoginInfo() {
		try {
			LoginUser loginAppUser = UserUtils.getLoginAppUser();
			GetUserLoginInfoVo getUserLoginInfoVo = service.getUserLoginInfo(loginAppUser.getUserId());
			return Message.success("成功",getUserLoginInfoVo);
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}

	}

	/**
	 * 通过id删除数据
	 * @author suxl
	 * @date Aug 27, 2020 10:39:27 AM
	 */
	@ApiOperation(value = "用户信息表删除", notes = "通过id删除用户信息表信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@PreAuthorize("hasAuthority('tb:sys:user:delete')")
	public Message delete(@RequestParam(value="id") Long id) {
		try {
			service.deleteById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}
	}

	/**
	 * 禁用用户
	 * @author 苏小林
	 * @date 2020/9/18 16:55
	 */
	@ApiOperation(value = "禁用用户", notes = "禁用用户。")
	@RequestMapping(value = "/disable", method = RequestMethod.GET)
	@PreAuthorize("hasAuthority('tb:sys:user:delete')")
	public Message disable(@RequestParam(value="id") Long id) {
		try {
			TbGlobalUser tbGlobalUser = new TbGlobalUser();
			tbGlobalUser.setUserId(id);
			tbGlobalUser.setStatus(1);
			service.updateById(tbGlobalUser);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
			return Message.error(1,"失败");
		}
	}

	/**
	 * 发送短信验证码
	 * @author 苏小林
	 * @date 2020/9/16 10:38
	 * @param: phoneNumber
	 */
	@ApiOperation(value = "发送短信验证码", notes = "发送短信验证码。")
	@RequestMapping(value = "/sendCode", method = RequestMethod.GET)
	public Message sendCode(@RequestParam("phoneNumber") String phoneNumber) {
		try {

			LoginUser byPhoneNumber = service.findByPhoneNumber(phoneNumber);
			if (byPhoneNumber == null) {
				return Message.error(1,"该用户不存在");
			}

			String s = stringRedisTemplate.opsForValue().get(phoneNumber + ":validateCode");
			if (StringUtils.isBlank(s)) {
				Message message = AliyunMessage.sendValidateCode(phoneNumber);
				Object code = message.get("code");
				if (!Objects.isNull(code)) {
					Integer integer = StringUtils.toInteger(code);
					if (integer == 0) {
						stringRedisTemplate.opsForValue().set(phoneNumber+":validateCode",String.valueOf(message.get("data")),5, TimeUnit.MINUTES);
						return Message.success("成功,请在5分钟内输入");
					} else {
						return Message.error(1,"失败");
					}
				}
			} else {
				return Message.success("不能重复发送");
			}
			return Message.success("成功");
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}
	}


	/**
	 * 忘记密码后-修改密码
	 * @author 苏小林
	 * @date 2020/9/16 10:57
	 */
	@ApiOperation(value = "忘记密码后-修改密码", notes = "忘记密码后-修改密码。")
	@RequestMapping(value = "/updatePwdForget", method = RequestMethod.POST)
	public Message updatePwdForget(@RequestBody Map<String,Object> data) {

		try {
			String authCode = StringUtils.getStringValue(data,"authCode");
			if (StringUtils.isNotBlank(authCode)) {
				authCode = RSACoder.decrypt(authCode, privateKey);
			} else {
				return Message.error(1,"验证码为空");
			}

			String password = StringUtils.getStringValue(data,"password");
			if (StringUtils.isNotBlank(password)) {
				password = RSACoder.decrypt(password, privateKey);

				String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
				if (!Pattern.matches(regex,password)) {
					return Message.error(1,"密码必须包含数字和字母,且长度在8-16之间");
				}
			} else {
				return Message.error(1,"密码为空");
			}

			String phoneNumber = StringUtils.getStringValue(data,"phoneNumber");
			if (StringUtils.isNotBlank(phoneNumber)) {
				phoneNumber = RSACoder.decrypt(phoneNumber, privateKey);
			} else {
				return Message.error(1,"手机号为空");
			}

			String s = stringRedisTemplate.opsForValue().get(phoneNumber + ":validateCode");
			if (StringUtils.isBlank(s)) {
				return Message.error(1,"验证码不存在");
			}
			if (s.equals(authCode)) {
				String encode = bCryptPasswordEncoder.encode(password);
				tbGlobalUserMapper.updatePwdByPhone(phoneNumber,encode);
			} else {
				return Message.error(1,"验证码不正确");
			}

			return Message.success("成功");
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}
	}


	/**
	 * 登录用户修改密码
	 * @author 苏小林
	 * @date 2020/9/17 13:27
	 * @param: data
	 * @return: com.xhsj.user.utils.Message
	 */
	@ApiOperation(value = "修改密码", notes = "修改密码。")
	@RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
	public Message updatePwd(@RequestBody Map<String,Object> data) {

		try {
			String oldPwd = StringUtils.getStringValue(data,"oldPwd");
			if (StringUtils.isNotBlank(oldPwd)) {
				oldPwd = RSACoder.decrypt(oldPwd, privateKey);
			} else {
				return Message.error(1,"原密码为空");
			}
			String newPwd = StringUtils.getStringValue(data,"newPwd");
			if (StringUtils.isNotBlank(newPwd)) {
				newPwd = RSACoder.decrypt(newPwd, privateKey);
			} else {
				return Message.error(1,"新密码为空");
			}

			Long userId = UserUtils.getLoginAppUser().getUserId();
			TbGlobalUser byId = service.getById(userId);
			boolean matches = bCryptPasswordEncoder.matches(oldPwd, byId.getPassword());
			if (matches) {
				byId.setPassword(bCryptPasswordEncoder.encode(newPwd));
				service.updateById(byId);
			} else {
				return Message.error(1,"原密码不正确");
			}
			return Message.success("成功");
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}

	}

	/**
	 * 获取登录后需要的信息
	 * @author 苏小林
	 * @date 2020/9/3 15:15
	 */
	@ApiOperation(value = "获取登录后需要的信息", notes = "获取登录后需要的信息。")
	@RequestMapping(value = "/getSystemInfo", method = RequestMethod.GET)
	public Message getSystemInfo() {

        try {
            // 所有职位
            List<MapQuery> allPositions = tbGlobalOrganizationMapper.findPositionList();

            // 所有部门
            List<MapQuery> allDepts = tbGlobalOrganizationMapper.organizationList();

			// 获取中文环境
			Comparator comparator = Collator.getInstance(Locale.CHINA);
			// 排序实现
			Collections.sort(allDepts, (e1, e2) -> {
				return comparator.compare(e1.getLabel(), e2.getLabel());
			});


            // 所有角色
            List<MapQuery> allRoles = tbGlobalRoleMapper.findRoles();

            // 所有用户
            List<MapQuery> allUsers = service.getAllUsers();

            Map<Object, Object> map = Maps.newHashMap();
            map.put("allUsers",allUsers);
            map.put("allRoles",allRoles);
            map.put("allDepts",allDepts);
            map.put("allPositions",allPositions);
            return Message.success("成功",map);
        } catch (Exception e) {
            log.error("失败:{}",e);
            return Message.error(1,"失败");
        }

    }

    /**
     * 查询所有用户-包含离职
     * @author 苏小林
     * @date 2020/9/19 12:10
     */
	@ApiOperation(value = "查询所有用户-包含离职", notes = "查询所有用户-包含离职。")
	@RequestMapping(value = "/findAllUsers", method = RequestMethod.GET)
    public Message findAllUsers() {
		try {
			List<MapQuery> allUsers = tbGlobalUserMapper.findAllUsers();
			return Message.success("成功",allUsers);
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}
	}

    /**
     * 查询用户入职id
     * @author 苏小林
     * @date 2020/9/15 18:05
     * @param: userId
     * @return: com.xhsj.user.utils.Message
     */
	@ApiOperation(value = "查询用户入职id", notes = "查询用户入职id。")
	@RequestMapping(value = "/getEntryIdByUserId", method = RequestMethod.GET)
    public Message getEntryIdByUserId(@RequestParam("userId") Long userId) {

		TbGlobalUser byId = service.getById(userId);
		return Message.success("成功",byId.getEntryId());

	}


    /**
     * 查询用户部门职位信息
     * @author 苏小林
     * @date 2020/9/9 9:22
     * @param: userId
     */
	@ApiOperation(value = "获取登录后需要的信息", notes = "获取登录后需要的信息。")
	@RequestMapping(value = "/getUserDeptAndPosition", method = RequestMethod.GET)
    public Message getUserDeptAndPosition(@RequestParam("userId") Long userId) {

		try {
			Map<String,Object> map = service.getUserDeptAndPosition(userId);
			return Message.success("成功",map);
		} catch (Exception e) {
			log.error("失败:{}",e);
			return Message.error(1,"失败");
		}

	}

	/**
	 * 查询所有用户
	 * @author 苏小林
	 * @date 2020/9/1 14:41
	 * @return: com.xhsj.user.utils.Message
	 */
	@ApiOperation(value = "查询所有用户", notes = "查询所有用户。")
	@RequestMapping(value = "/getAllUsers", method = RequestMethod.GET)
	public Message getAllUsers() {
		return Message.success("成功",service.getAllUsers());
	}

	/**
	 * 批量删除
	 * @author suxl
	 * @date Aug 27, 2020 10:39:27 AM
	 */
	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	public Message batchDelete(@RequestBody List<String> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }

    /**
    * 分页查询数据
    * @author suxl
    * @date Aug 27, 2020 10:39:27 AM
    */
	@ApiOperation(value = "分页查询用户信息表list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('tb:sys:user:view')")
	public Message findList(@RequestBody BaseParam baseParam) {
        try {
        	IPage<FindUserListVo> selectPage = service.selectPage(baseParam);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

    /**
    * 通过id获取实体类
    * @author suxl
    * @date Aug 27, 2020 10:39:27 AM
    */
	@ApiOperation(value = "通过id获取用户信息表实体类", notes = "通过id获取用户信息表实体类。")
	@RequestMapping(value="/getUserInfoById",method = RequestMethod.GET)
    // @PreAuthorize("hasAuthority('tb:sys:user:view')")
	public Message getUserInfoById(@RequestParam(value="id") String id) {
		return Message.success("成功",service.getUserInfoById(id));
	}

    /**
    * 通过id查询详细信息
    * @author suxl
    * @date Aug 27, 2020 10:39:27 AM
    */
	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
	@PreAuthorize("hasAuthority('tb:sys:user:view')")
	public Message detail(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}



	/**
	 * 退出
	 *
	 */
	@GetMapping("/logout")
	public Message logout(@RequestHeader(required = false, value = "Authorization") String token) {
		String access_token = "";
		if (StringUtils.isNotBlank(token)) {
			access_token = token.substring(OAuth2AccessToken.BEARER_TYPE.length());
		}
		boolean flag = tokenServices.revokeToken(access_token);
		if (flag) {
			SecurityContextHolder.getContext().getAuthentication();
			log.info("退出成功");
			return Message.success("成功");
		}else{
			return Message.error("失败");
		}
	}

	/**
	 * 人员列表
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "人员列表", notes = "人员列表")
	@PostMapping(value="/getUserList")
	public Message getUserList(@RequestBody @Valid UserListDto data, BindingResult bindingResult) {
		log.info("人员列表参数{}", data);
		if (bindingResult.hasErrors()) {
			log.info(bindingResult.getFieldError().getDefaultMessage());
			return Message.error(1,bindingResult.getFieldError().getDefaultMessage());
		}
        IPage<UserListQuery> userList = service.getUserList(data);
        return Message.success("成功",userList.getRecords(),userList.getTotal(),userList.getPages());
	}

	/**
	 * 我的人员列表
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "我的人员列表", notes = "我的人员列表")
	@PostMapping(value="/getMyUserList")
	@PreAuthorize("hasAnyAuthority('tb:sys:user:my:view','tb:hr:approval:dimission:list:view')")
	public Message getMyUserList(@RequestBody @Valid UserListDto data, BindingResult bindingResult) {
		log.info("我的人员列表参数{}", data);
		if (bindingResult.hasErrors()) {
			log.info(bindingResult.getFieldError().getDefaultMessage());
			return Message.error(1,bindingResult.getFieldError().getDefaultMessage());
		}
        return Message.success("成功",service.getMyUserList(data));
	}

	/**
	 * 人员详细信息 @PreAuthorize("hasAuthority('tb:sys:user:all:view')")
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "人员详细信息", notes = "人员详细信息")
	@GetMapping(value="/getUserDetail")
	@PreAuthorize("hasAuthority('tb:sys:user:my:view')")
	public Message getUserDetail(@RequestParam(value = "userId") Long userId) {
		log.info("人员详细信息参数{}", userId);
		return Message.success("成功",service.getUserDetail(userId));
	}

	/**
	 * 人员详细信息 @PreAuthorize("hasAuthority('tb:sys:user:all:view')")
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "人员详细信息", notes = "人员详细信息")
	@GetMapping(value="/getAllDataDetails")
	@PreAuthorize("hasAuthority('tb:sys:user:detail:view')")
	public Message getAllDataDetails(@RequestParam(value = "userId") Long userId) {
		log.info("人员详细信息参数{}", userId);
		return Message.success("成功",service.getUserDetail(userId));
	}


	@GetMapping(value="/getDetailUserInfoToApp")
	public Message getDetailUserInfoToApp(@RequestParam(value = "userId") Long userId) {
		log.info("人员详细信息参数{}", userId);
		return Message.success("成功",service.getDetailUserInfoToApp(userId));
	}

	/**
	 * 人员修改
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "人员修改", notes = "人员修改")
	@PostMapping(value="/updateUserDetail")
	@PreAuthorize("hasAuthority('tb:sys:user:detail:edit')")
	public Message updateUserDetail(@RequestBody UpdateUserDetailDto data) throws Exception {
		try {
			log.info("人员修改参数{}", data);
			service.updateUserDetail(data);
			return Message.success("成功");
		}catch (Exception e){
			return Message.error(1,e.getMessage());
		}

	}

	/**
	 * 获取用户基本信息 用于调岗： 部门 职位 上级领导 薪资
	 * @return
	 */
	@ApiOperation(value = "获取用户基本信息 用于调岗： 部门 职位 上级领导 薪资", notes = "获取用户基本信息 用于调岗： 部门 职位 上级领导 薪资")
	@GetMapping("/loadUserInfo")
	public Message loadUserInfo(Long userId) throws Exception {
		LoadUserInfoQuery user = service.loadUserInfo(userId);
		return Message.success("成功",user);
	}

	/**
	 * 人事允许转正
	 * @author liuqinghua
	 * @date Sep 8, 2020 3:02:09 PM
	 */
	@ApiOperation(value = "人事允许转正", notes = "人事允许转正")
	@GetMapping(value="/becomeRegularButton")
	@PreAuthorize("hasAuthority('tb:sys:user:become:regular:button')")
	@OperationPointCut(module = "HR模块",operation = "人事点击允许转正按钮")
	public Message becomeRegularButton(@RequestParam(value = "userId") Long userId) throws Exception {
		service.becomeRegularButton(userId);
		return Message.success("成功");
	}


	/**
	 * 人员数量统计
	 * @author 苏小林
	 * @date 2020/9/14 14:36
	 * @param: date
	 */
	@ApiOperation(value = "人员数量统计", notes = "人员数量统计")
	@GetMapping(value="/personNumberStatistic")
	public Message personNumberStatistic(@RequestParam(value = "date",required = false) String date) {
		long l = System.currentTimeMillis();

		List<Object> list = Lists.newArrayList();
		// 查询每月面试人数
		int[] countByDate = tbHrInterviewRegistrationService.getCountByDate(date);

		// 查询每月入职人数
		int[] rzArray = TbHrApprovalEntryApplyService.getCountByDate(date);

		// 查询每月转正人数
		int[] zzArray = tbHrApprovalBecomeRegularApplyService.getCountByDate(date);

		// 查询每月离职人数
		int[] lzArray = tbHrApprovalDimissionApplyService.getCountByDate(date);

		list.add(countByDate);
		list.add(rzArray);
		list.add(zzArray);
		list.add(lzArray);
		long l1 = System.currentTimeMillis();
		System.err.println(l1-l);
		return Message.success("success",list);
	}


	/**
	 * 查询在职人员统计
	 * @author 苏小林
	 * @date 2020/9/14 18:27
	 * @param: date
	 * @return: com.xhsj.user.utils.Message
	 */
	@ApiOperation(value = "查询在职人员统计", notes = "查询在职人员统计")
	@GetMapping(value="/findInServiceStaff")
	public Message findInServiceStaff(@RequestParam(value = "date",required = false) String date) {
		try {
			List<Map> list = service.findInServiceStaff(date);
			return Message.success("成功",list);
		} catch (ParseException e) {
			log.error("查询异常:{}",e);
			return Message.error(1,"失败");
		}
	}

	   /**
	       * @Description:  获取在职员工
	       * @Param:  无
	       * @return:com.xhsj.user.hr.process.processDefinition.query.MapQuery
	       * @Author: liuqinghua
	       * @Date: 2020/11/10
	       */
	   @ApiOperation(value = "获取在职员工", notes = "获取在职员工")
	   @GetMapping(value="/getOnTheJobEmployees")
	   public Message getOnTheJobEmployees() {
		   try {
			   List<MapQuery> list = service.getOnTheJobEmployees();
			   return Message.success("成功",list);
		   } catch (Exception e) {
			   log.error("查询异常:{}",e);
			   return Message.error(1,"失败");
		   }
	   }

	/**
	 * 通过用户id查询部门相关信息
	 *
	 * @param userId
	 * @autoor suxiaolin
	 */
	@GetMapping("/getDeptByUserId")
	public Map<String, Object> getDeptByUserId(Long userId) {
		// 通过用户id获取部门信息
		Map<String, Object> map = tbGlobalUserMapper.getDeptByUserId(userId);
		return map;
	}

	/**
	 * 查询用户信息
	 * @author 苏小林
	 * @date 2021/4/7 15:17
	 * @return: com.xhsj.user.utils.Message
	 */
	@GetMapping("/getUserInfo")
	public Message getUserInfo() {
		try {
			UserInfoToAppVo userInfoToAppVo = service.getUserInfoToApp();

			return Message.success("success",userInfoToAppVo);
		} catch (Exception e) {
			log.error("查询异常:{}",e);
			return Message.error(1,"失败");
		}
	}

}

